package com.thinkinjava.genericity.coffee;

import com.thinkinjava.genericity.Generator;
import org.jetbrains.annotations.NotNull;

import java.util.Iterator;
import java.util.Random;
import java.util.Spliterator;
import java.util.function.Consumer;

/**
 * @Description coffee泛型类
 * @Author
 * @Date 2020/1/21 15:56
 **/
public class CoffeeGenerator implements Generator<Coffee>,Iterable<Coffee> {

    private Class[] types ={Latte.class,Mocha.class};

    private  static Random random = new Random(47);

    private  int size;

    public CoffeeGenerator(int size) {
        this.size = size;
    }



    @NotNull
    @Override
    public Iterator<Coffee> iterator() {
        return null;
    }

    @Override
    public void forEach(Consumer<? super Coffee> action) {

    }

    @Override
    public Spliterator<Coffee> spliterator() {
        return null;
    }

    @Override
    public Coffee next() {
      try {
          return (Coffee) types[random.nextInt(types.length)].newInstance();
      }catch (Exception e){
            throw new RuntimeException();
      }
    }

    public static void main(String[] args) {
        CoffeeGenerator coffees = new CoffeeGenerator(10);
        for (int i = 0; i < 10; i++) {
            System.out.println(coffees.next());
        }
    }
}
